package com.hj.aiagent.advisor;

import org.springframework.ai.chat.client.advisor.api.*;
import reactor.core.publisher.Flux;

public class MyCustomAdvisor implements CallAroundAdvisor, StreamAroundAdvisor {
    @Override
    public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) {
        //1. 处理请求

        //2. 调用下一个拦截器
        AdvisedResponse advisedResponse = chain.nextAroundCall(advisedRequest);

        //3. 处理响应请求
        return advisedResponse;
    }

    @Override
    public Flux<AdvisedResponse> aroundStream(AdvisedRequest advisedRequest, StreamAroundAdvisorChain chain) {
        //1. 处理请求

        //2. 调用下一个拦截器
        Flux<AdvisedResponse> flux = chain.nextAroundStream(advisedRequest);
        return flux.map(response -> {
            //3. 处理响应请求
            return response;
        });
    }

    @Override
    public String getName() {
        return "我自定义的拦截器";
    }

    @Override
    public int getOrder() {
        // 拦截器的优先级，数字越小越先执行
        return 0;
    }
    // 实现方法...
}
